﻿using System;

using System.Collections.Generic;
using System.Text;
using Fluid.Controls;
using System.Drawing;
using PasswordSafe.ListBoxes;
using PasswordSafe.Classes;

namespace PasswordSafe
{
    public class CategoriesPanel:FluidPanel
    {
        private FluidHeader header = new FluidHeader();
        private CategoryListBox listBox = new CategoryListBox();

        protected override void InitControl()
        {
            base.InitControl();
            Bounds = new Rectangle(0, 0, 240, 300);
            BackColor = Color.Green;
            Anchor = AnchorAll;
            const int h = 32;
            header.Bounds = new Rectangle(0, 0, 240, h);
            listBox.Bounds = new Rectangle(0, h, 240, 300 - h);
            header.Anchor = AnchorTLR;
            listBox.Anchor = AnchorAll;
            header.BackButton.Shape = ButtonShape.Rounded;
            header.BackButton.Visible = true;
            header.BackButton.Text = "OK";
            header.Title = "Choose Categories";
            header.BackButton.Click += new EventHandler(BackButton_Click);


            Controls.Add(header);
            Controls.Add(listBox);
        }


        public List<CategoryListBoxItem> Categories { get { return listBox.Categories; } }

        void BackButton_Click(object sender, EventArgs e)
        {
            ListBuilder.Instance.AddCategories(Categories);
            Close();
        }

        private static CategoriesPanel instance;

        public static CategoriesPanel Instance
        {
            get
            {
                if (instance == null) instance = new CategoriesPanel();
                return instance;
            }
        }


        public override void Focus()
        {
            listBox.Focus();
        }


        internal void UpdateData()
        {
            listBox.UpdateData();
        }
    }
}
